package demo07;

import java.time.*;

/**
 * @author: WangPeng
 * @createTime: 2022/11/07 16:28
 * @description:
 * @version: v1.0
 */
public class Test01 {
    public static void main(String[] args) {
    //指定日期时间--of()
        //创建一个指定日期时间的类--LocalDateTime.of
        LocalDateTime localDateTime = LocalDateTime.of(2019, 9, 1, 12, 15, 19);
        System.out.println("指定的日期时间："+localDateTime);
        //创建一个指定日期
        LocalDate localDate = LocalDate.of(2020, 9, 21);
        System.out.println("指定的日期："+localDate);
        //创建一个指定时间
        LocalTime localTime = LocalTime.of(12, 45, 31);
        System.out.println("指定的时间："+localTime);
    //获取当前时间--now()
        //获取当前日期时间
        LocalDateTime now1 = LocalDateTime.now();
        System.out.println("当前的日期时间："+now1);
        //获取当前时间
        LocalTime now2 = LocalTime.now();
        System.out.println("当前的时间："+now2);
        //获取当前日期
        LocalDate now3 = LocalDate.now();
        System.out.println("当前的日期："+now3);

        //日期中常见的方法--get方法
        int year = localDateTime.getYear();
        System.out.println("year = " + year);
        int month = localDateTime.getMonthValue();
        System.out.println("month = " + month);
        int dayOfMonth = localDateTime.getDayOfMonth();
        System.out.println("dayOfMonth = " + dayOfMonth);
        int hour = localDateTime.getHour();
        System.out.println("hour = " + hour);
        int minute = localDateTime.getMinute();
        System.out.println("minute = " + minute);
        int second = localDateTime.getSecond();
        System.out.println("second = " + second);

    }

    public static void getLocaTime(){
        //创建一个指定时间
        LocalTime localTime = LocalTime.of(12, 45, 31);
        System.out.println("指定的时间："+localTime);
        //获取当前时间
        LocalTime now = LocalTime.now();
        System.out.println("当前的时间："+now);
        //日期中常见的方法--get方法
        int hour = now.getHour();
        System.out.println("hour = " + hour);
        int minute = now.getMinute();
        System.out.println("minute = " + minute);
        int second = now.getSecond();
        System.out.println("second = " + second);
    }

    public static void getLocalDate(){
        //创建一个指定日期
        LocalDate localDate = LocalDate.of(2020, 9, 21);
        System.out.println("指定的日期："+localDate);
        //获取当前日期
        LocalDate now = LocalDate.now();
        System.out.println("当前的日期："+now);
        //日期中常见的方法--get方法
        int year = now.getYear();
        System.out.println("year = " + year);
        int month = now.getMonthValue();
        System.out.println("month = " + month);
        int dayOfMonth = now.getDayOfMonth();
        System.out.println("dayOfMonth = " + dayOfMonth);
        int value = now.getDayOfWeek().getValue();
        System.out.println("value = " + value);
    }

    public static void getLocalDateTIme(){
        //创建一个指定日期时间的类--LocalDateTime.of
        LocalDateTime localDateTime = LocalDateTime.of(2019, 9, 1, 12, 15, 19);
        System.out.println("指定的日期时间："+localDateTime);
        //获取当前日期时间
        LocalDateTime now = LocalDateTime.now();
        System.out.println("当前的日期时间："+now);
        //日期中常见的方法--get方法
        int year = localDateTime.getYear();
        System.out.println("year = " + year);
        int month = localDateTime.getMonthValue();
        System.out.println("month = " + month);
        int dayOfMonth = localDateTime.getDayOfMonth();
        System.out.println("dayOfMonth = " + dayOfMonth);
        int hour = localDateTime.getHour();
        System.out.println("hour = " + hour);
        int minute = localDateTime.getMinute();
        System.out.println("minute = " + minute);
        int second = localDateTime.getSecond();
        System.out.println("second = " + second);
    }
}
